package com.haoniu.web.controller.module;

import com.haoniu.common.utils.StringUtils;
import com.haoniu.framework.util.ShiroUtils;
import com.haoniu.module.domain.dto.UserWalletTraDTO;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.haoniu.common.annotation.Log;
import com.haoniu.common.enums.BusinessType;
import com.haoniu.module.domain.database.UserWalletTransfer;
import com.haoniu.module.service.UserWalletTransferService;
import com.haoniu.web.core.base.BaseController;
import com.haoniu.framework.web.page.TableDataInfo;
import com.haoniu.common.base.AjaxResult;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 转账记录 信息操作处理
 *
 * @author houyijun
 * @date 2019-01-25
 */
@Controller
@RequestMapping("/module/userWalletTransfer")
public class UserWalletTransferController extends BaseController
{
    private String prefix = "module/userWalletTransfer";

	@Autowired
	private UserWalletTransferService userWalletTransferService;

	@RequiresPermissions("module:userWalletTransfer:view")
	@GetMapping()
	public String userWalletTransfer()
	{
	    return prefix + "/userWalletTransfer";
	}

	/**
	 * 查询转账记录列表
	 */
	@RequiresPermissions("module:userWalletTransfer:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(UserWalletTransfer userWalletTransferReq) {
		startPage();
        //List<UserWalletTransfer> list = userWalletTransferService.selectUserWalletTransferList(userWalletTransferReq);
		List<UserWalletTraDTO> list = userWalletTransferService.userWalletTraList(userWalletTransferReq);

		return getDataTable(list);
	}

	/**
	 * 新增转账记录
	 */
	@GetMapping("/add")
	public String add() {
	    return prefix + "/add";
	}

	/**
	 * 新增保存转账记录
	 */
	@RequiresPermissions("module:userWalletTransfer:add")
	@Log(title = "转账记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(UserWalletTransfer userWalletTransfer) {
        userWalletTransfer.setCreateBy(ShiroUtils.getLoginName());
		return toAjax(userWalletTransferService.insertUserWalletTransfer(userWalletTransfer));
	}

	/**
	 * 修改转账记录
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap) {
		UserWalletTransfer userWalletTransfer = userWalletTransferService.selectUserWalletTransferById(id);
		mmap.put("userWalletTransfer", userWalletTransfer);
	    return prefix + "/edit";
	}

	/**
	 * 修改保存转账记录
	 */
	@RequiresPermissions("module:userWalletTransfer:edit")
	@Log(title = "转账记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(UserWalletTransfer userWalletTransfer) {
        userWalletTransfer.setUpdateBy(ShiroUtils.getLoginName());
		return toAjax(userWalletTransferService.updateUserWalletTransfer(userWalletTransfer));
	}

	/**
	 * 删除转账记录
	 */
	@RequiresPermissions("module:userWalletTransfer:remove")
	@Log(title = "转账记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(userWalletTransferService.deleteUserWalletTransferByIds(ids));
	}

}
